//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package nc.bs.fipub.rulecheck;

import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import nc.bs.framework.common.NCLocator;
import nc.bs.glcom.ass.assitem.cache.AccAssItemCache;
import nc.bs.logging.Log;
import nc.bs.logging.Logger;
import nc.bs.ml.NCLangResOnserver;
import nc.itf.fipub.rulecheck.IRuleCheckPubService;
import nc.pubitf.bd.accessor.GeneralAccessorFactory;
import nc.pubitf.bd.accessor.IGeneralAccessor;
import nc.pubitf.uapbd.IAccountPubService;
import nc.vo.bd.accessor.IBDData;
import nc.vo.bd.account.AccAssVO;
import nc.vo.bd.account.AccountVO;
import nc.vo.fipub.freevalue.account.proxy.AccAssGL;
import nc.vo.fipub.rule.DynamicSort;
import nc.vo.fipub.rulecheck.OperationResultVO;
import nc.vo.fipub.rulecheck.RuleQueryVO;
import nc.vo.fipub.rulecheck.RuleTypeVO;
import nc.vo.fipub.rulecontrol.RuleBindVO;
import nc.vo.fipub.rulecontrol.RuleHeadVO;
import nc.vo.fipub.rulecontrol.RuleItemVO;
import nc.vo.fipub.utils.StrTools;
import nc.vo.glcom.ass.AssVO;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pub.BusinessException;
import org.apache.commons.lang3.StringUtils;

public class RuleCheckBO {
    private static int itemSize = 10;

    public RuleCheckBO() {
    }

    private String[] buildCheckType(String[] pk_strCrossType, AssVO[] assVO) throws RemoteException {
        int l_CroosTypeLen = pk_strCrossType.length;
        String[] l_Type = new String[l_CroosTypeLen];
        int l_AssVOLen = assVO.length;
        int l_count = 0;
        boolean l_isAdded = false;
        int l_next = l_AssVOLen;

        for(int i = 0; i < l_CroosTypeLen; ++i) {
            l_isAdded = false;
            int j = 0;
            if (l_count < l_AssVOLen) {
                for(int var12 = 0; var12 < l_AssVOLen; ++var12) {
                    if (pk_strCrossType[i].equals(assVO[var12].getPk_Checktype())) {
                        l_Type[var12] = assVO[var12].getPk_Checktype();
                        ++l_count;
                        l_isAdded = true;
                        break;
                    }
                }
            }

            if (!l_isAdded) {
                l_Type[l_next] = pk_strCrossType[i];
                ++l_next;
            }
        }

        return l_Type;
    }

    private OperationResultVO[] buildResultVO(RuleTypeVO[] rtVO, int newCount, boolean b_CopyType) throws RemoteException {
        if (newCount <= 0) {
            return null;
        } else {
            OperationResultVO[] rule = new OperationResultVO[newCount];

            for(int i = 0; i < newCount; ++i) {
                rule[i] = new OperationResultVO();
            }

            int l_loc = 0;

            for(int i = 0; i < rtVO.length; ++i) {
                if (rtVO[i].isOK() == b_CopyType) {
                    if (rtVO[i].isForbid()) {
                        rule[l_loc].m_intSuccess = 2;
                    } else {
                        rule[l_loc].m_intSuccess = 1;
                    }

                    OperationResultVO var10000 = rule[l_loc];
                    String var10001 = NCLangResOnserver.getInstance().getStrByID("200243", "UPP200243-000000");
                    var10000.m_userIdentical = var10001 + rtVO[i].getRuleName();
                    ++l_loc;
                }
            }

            return rule;
        }
    }

    private RuleTypeVO[] checkRuleTypeVO(RuleTypeVO[] rtVO, String[] pk_strCrossType) throws RemoteException, Exception {
        RuleTypeVO[] ruleVO = null;
        int l_RtVOLen = rtVO.length;
        int l_CrossTypeLen = pk_strCrossType.length;
        int l_newCount = l_RtVOLen;

        for(int i = 0; i < l_RtVOLen; ++i) {
            int l_count = 0;
            rtVO[i].setOK(false);
            --l_newCount;

            for(int k = 0; k < l_CrossTypeLen; ++k) {
                if (rtVO[i].isIN(pk_strCrossType[k])) {
                    ++l_count;
                }

                if (l_count == rtVO[i].getCount()) {
                    rtVO[i].setOK(true);
                    ++l_newCount;
                    break;
                }
            }
        }

        ruleVO = this.copyVO(rtVO, l_newCount, true);
        return ruleVO;
    }

    private RuleTypeVO[] checkRuleTypeVO(RuleTypeVO[] rtVO, String[] pk_strCrossType, AssVO[] assVO, String get_strCrossType) throws RemoteException, Exception {
        RuleTypeVO[] ruleVO = null;
        int l_RtVOLen = rtVO.length;
        int l_CrossTypeLen = pk_strCrossType.length;
        String[] pk_CrossType = this.buildCheckType(pk_strCrossType, assVO);
        int newCount = l_RtVOLen;
        int l_assVOLen = assVO.length;

        for(int i = 0; i < l_RtVOLen; ++i) {
            String sql = "";
            RuleTypeVO tmpvo = null;
            if (rtVO[i].isIN(get_strCrossType)) {
                tmpvo = rtVO[i];
                String var10000 = tmpvo.getColName(get_strCrossType);
                sql = "select distinct " + var10000 + " as item  from gl_rule_b where pk_rule = '" + tmpvo.getPk_rule() + "' and " + tmpvo.getColName(get_strCrossType) + " != 'NULL' and style = '1' ";
                int l_count = 0;
                rtVO[i].setOK(false);
                rtVO[i].setSQL("");
                if (l_CrossTypeLen == 0) {
                    rtVO[i].setSQL(sql);
                    rtVO[i].setOK(true);
                    break;
                }

                boolean isOK = false;
                boolean isOK2 = false;

                for(int k = 0; k < l_CrossTypeLen; ++k) {
                    String l_col = tmpvo.getColName(pk_CrossType[k]);
                    if (l_col != null) {
                        ++l_count;
                        if (k < l_assVOLen) {
                            isOK = true;
                            if (assVO[k].getPk_Checkvalue() != null) {
                                sql = sql + " and (" + l_col + " = '" + assVO[k].getPk_Checkvalue();
                            } else {
                                sql = sql + " and (" + l_col + " = 'NULL'";
                            }

                            sql = sql + "' or " + l_col + " = 'ALL')";
                        }
                    }

                    if (l_count == rtVO[i].getCount()) {
                        rtVO[i].setOK(true);
                        isOK2 = true;
                        break;
                    }
                }

                if (!isOK && !isOK2) {
                    rtVO[i].setSQL("");
                    rtVO[i].setOK(false);
                    --newCount;
                } else {
                    rtVO[i].setSQL(sql);
                    rtVO[i].setOK(true);
                }
            } else {
                --newCount;
                rtVO[i].setOK(false);
            }
        }

        ruleVO = this.copyVO(rtVO, newCount, true);
        return ruleVO;
    }

    private RuleTypeVO[] checkRuleTypeVOs(RuleTypeVO[] rtVO, AssVO[] assVO) throws RemoteException, Exception {
        RuleTypeVO[] rule = null;
        int l_RtVOLen = rtVO.length;
        int l_assVOlen = assVO.length;
        int l_newCount = l_RtVOLen;
        RuleTypeVO tmpvo = null;

        for(int i = 0; i < l_RtVOLen; ++i) {
            String sql = "";
            tmpvo = rtVO[i];
            int l_count = 0;
            int l_icount = tmpvo.getCount();
            sql = sql + "select distinct 1 from gl_rule_b where pk_rule= '" + tmpvo.getPk_rule() + "' ";

            for(int k = 0; k < l_assVOlen; ++k) {
                String l_col = tmpvo.getColName(assVO[k].getPk_Checktype());
                if (l_col != null) {
                    if (assVO[k].getPk_Checkvalue() != null) {
                        sql = sql + " and (" + l_col + " = '" + assVO[k].getPk_Checkvalue();
                        sql = sql + "' or " + l_col + " = 'ALL')";
                    } else {
                        sql = sql + " and (" + l_col + " = 'NULL'";
                        sql = sql + " or " + l_col + " = 'ALL')";
                    }

                    ++l_count;
                }

                if (l_count == l_icount) {
                    break;
                }
            }

            if (l_count != l_icount) {
                rtVO[i].setSQL("");
                rtVO[i].setOK(false);
                --l_newCount;
            } else {
                rtVO[i].setSQL(sql);
                rtVO[i].setOK(true);
            }
        }

        rule = this.copyVO(rtVO, l_newCount, true);
        return rule;
    }

    private RuleTypeVO[][] checkRuleTypeVOs(RuleTypeVO[] rtVO, int begin, int end, RuleQueryVO[] rqVO, int[] idx) throws RemoteException, Exception {
        int l_RtVOLen = rtVO.length;
        int sqlcount = end - begin + 1;
        RuleTypeVO[][] rule = new RuleTypeVO[sqlcount][rtVO.length];

        for(int i = 0; i < l_RtVOLen; ++i) {
            int l_count = 0;
            String sql = "select distinct 1 from gl_rule_b where pk_rule= '" + rtVO[i].getPk_rule() + "' and style = '1'";
            String sql1 = "";

            for(int k = begin; k <= end; ++k) {
                l_count = 0;
                AssVO[] assVO = rqVO[idx[k]].getVO();
                int l_assLen = assVO.length;
                int[] valueLoc = new int[l_assLen];
                String[] sqls = new String[l_assLen];

                for(int l = 0; l < l_assLen; ++l) {
                    if (rtVO[i].isIN(assVO[l].getPk_Checktype())) {
                        sqls[l_count] = rtVO[i].getColName(assVO[l].getPk_Checktype());
                        valueLoc[l_count] = l;
                        ++l_count;
                    }

                    if (l_count == rtVO[i].getCount()) {
                        break;
                    }
                }

                sql1 = "";

                for(int j = 0; j < l_count; ++j) {
                    String l_col = sqls[j];
                    AssVO[] tm = rqVO[idx[k]].getVO();
                    if (tm[valueLoc[j]].getPk_Checkvalue() != null) {
                        sql1 = sql1 + " and (" + l_col + " = '" + tm[valueLoc[j]].getPk_Checkvalue();
                        sql1 = sql1 + "' or " + l_col + " = 'ALL')";
                    } else {
                        sql1 = sql1 + " and (" + l_col + " = 'NULL'";
                        sql1 = sql1 + " or " + l_col + " = 'ALL')";
                    }
                }

                rule[k - begin][i] = (RuleTypeVO)rtVO[i].clone();
                rule[k - begin][i].setSQL(sql + sql1);
            }
        }

        return rule;
    }

    public OperationResultVO[] checkValue(RuleQueryVO rqVO) throws BusinessException {
        String pk_strCorp = rqVO.getPk_glorgbook();
        String pk_strSubject = rqVO.getSubject();
        String pk_strBook = rqVO.getPk_book();
        String[] pk_strCrossType = rqVO.getPk_StrCrossType();
        AssVO[] assVO = rqVO.getVO();
        if (assVO != null && assVO.length != 0) {
            try {
                RuleCheckDMO dmo = new RuleCheckDMO();
                RuleTypeVO[] rtVO = dmo.getAllBindRule(pk_strCorp, pk_strSubject, pk_strBook);
                rtVO = this.checkRuleTypeVOs(rtVO, assVO);
                OperationResultVO[] ret = null;
                if (rtVO != null && rtVO.length > 0) {
                    int count = dmo.checkDetail(rtVO);
                    if (count > 0) {
                        ret = this.buildResultVO(rtVO, count, false);
                    }
                }

                return ret;
            } catch (Exception e) {
                throw new BusinessException(e.getMessage());
            }
        } else {
            return null;
        }
    }

    private void checkValues(OperationResultVO[][] ret, int begin, int end, RuleQueryVO[] rqVO, int[] idx) throws BusinessException {
        int t = idx[begin];
        String pk_strCorp = rqVO[t].getPk_glorgbook();
        String pk_strSubject = rqVO[t].getSubject();
        String pk_strBook = rqVO[t].getPk_book();
        AssVO[] vos = rqVO[t].getVO();
        if (vos != null && vos.length != 0) {
            try {
                RuleCheckDMO dmo = new RuleCheckDMO();
                RuleTypeVO[] rtVO = dmo.getAllBindRule(pk_strCorp, pk_strSubject, pk_strBook);
                RuleTypeVO[][] rtvot = null;
                if (rtVO != null) {
                    rtvot = this.checkRuleTypeVOs(rtVO, begin, end, rqVO, idx);
                }

                if (rtvot != null && rtvot.length > 0) {
                    int[] l_count = dmo.checkDetails(rtvot);

                    for(int i = 0; i < l_count.length; ++i) {
                        if (l_count[i] > 0) {
                            ret[idx[i + begin]] = this.buildResultVO(rtvot[i], l_count[i], true);
                        } else {
                            ret[idx[i + begin]] = null;
                        }
                    }
                }

            } catch (Exception e) {
                throw new BusinessException(e.getMessage());
            }
        }
    }

    public OperationResultVO[][] checkValues(RuleQueryVO[] rqVO) throws BusinessException {
        int l_RqVOLen = rqVO.length;
        OperationResultVO[][] ret = new OperationResultVO[l_RqVOLen][];

        for(int i = 0; i < l_RqVOLen; ++i) {
            ret[i] = this.checkValue(rqVO[i]);
        }

        return ret;
    }

    public OperationResultVO[][] checkValuesGroupBySubject(RuleQueryVO[] rqVO, HashMap tempaccsubj) throws BusinessException {
        if (rqVO != null && rqVO.length > 0) {
            OperationResultVO[][] ret = new OperationResultVO[rqVO.length][];
            Set<String> pk_orgSet = new HashSet();

            for(int i = 0; i < rqVO.length; ++i) {
                pk_orgSet.add(rqVO[i].getPk_corp());
            }

            String[] pk_orgs = new String[pk_orgSet.size()];
            pk_orgSet.toArray(pk_orgs);
            String pk_group = rqVO[0].getPk_group();
            RuleHeadVO[] heads = ((IRuleCheckPubService)NCLocator.getInstance().lookup(IRuleCheckPubService.class)).queryRuleVosByOrg(pk_orgs, pk_group);
            if (heads == null) {
                return null;
            } else {
                HashMap<String, List<RuleHeadVO>> ruleMap = new HashMap();
                List<RuleHeadVO> headList = null;
                List<RuleHeadVO> groupList = new LinkedList();

                for(RuleHeadVO head : heads) {
                    if (pk_group.equals(head.getPk_org())) {
                        groupList.add(head);
                    } else {
                        headList = (List)ruleMap.get(head.getPk_org());
                        if (headList == null) {
                            headList = new LinkedList();
                            ruleMap.put(head.getPk_org(), headList);
                        }

                        headList.add(head);
                    }
                }

                if (groupList.size() > 0) {
                    for(String str : pk_orgs) {
                        headList = (List)ruleMap.get(str);
                        if (headList == null) {
                            headList = new LinkedList();
                            ruleMap.put(str, headList);
                        }

                        headList.addAll(groupList);
                    }
                }

                for(int i = 0; i < rqVO.length; ++i) {
                    headList = (List)ruleMap.get(rqVO[i].getPk_corp());
                    if (headList != null) {
                        this.checkValues(ret, rqVO[i], (RuleHeadVO[])headList.toArray(new RuleHeadVO[0]), i, (AccountVO)tempaccsubj.get(rqVO[i].getSubject()));
                    }
                }

                return ret;
            }
        } else {
            return null;
        }
    }

    private void checkValues(OperationResultVO[][] ret, RuleQueryVO ruleQueryVO, RuleHeadVO[] rules, int index, AccountVO account) throws BusinessException {
        if (rules != null && rules.length > 0) {
            HashSet<RuleHeadVO> vos = new HashSet();

            for(RuleHeadVO ruleHeadVO : rules) {
                vos.add(ruleHeadVO);
            }

            if (vos.size() != 0) {
                rules = (RuleHeadVO[])vos.toArray(new RuleHeadVO[0]);
                AssVO[] assVOs = ruleQueryVO.getVO();
                if (assVOs != null && assVOs.length > 0) {
                    OperationResultVO[] result = null;
                    OperationResultVO resultVO = null;
                    RuleHeadVO resultRule = null;
                    List<OperationResultVO> listTemp = new ArrayList();
                    HashMap<String, String> isNullAss = new HashMap();
                    if (account.getAccass() != null && account.getAccass().length > 0) {
                        for(AccAssVO assvo : account.getAccass()) {
                            isNullAss.put(assvo.getPk_entity(), assvo.getIsempty() != null && !assvo.getIsempty().booleanValue() ? "N" : "Y");
                        }
                    }

                    for(AssVO ass : assVOs) {
                        if (null == ass) {
                            continue;
                        }

                        if (!"Y".equals(isNullAss.get(ass.getPk_Checktype())) || !StrTools.isNullStr(ass.getPk_Checkvalue())) {
                            resultRule = this.checkValue(ruleQueryVO, rules, ass);
                            if (resultRule != null) {
                                result = ret[index];
                                if (result == null) {
                                    result = new OperationResultVO[0];
                                }

                                resultVO = new OperationResultVO();
                                resultVO.m_intSuccess = 2;
                                String var10001 = NCLangRes4VoTransl.getNCLangRes().getStrByID("20v61017_0", "020v61017-0263");
                                resultVO.m_strDescription = var10001 + ruleQueryVO.getRowIndex() + NCLangRes4VoTransl.getNCLangRes().getStrByID("20v61017_0", "020v61017-0264") + resultRule.getName();
                                listTemp.addAll(Arrays.asList(result));
                                listTemp.add(resultVO);
                                ret[index] = (OperationResultVO[])listTemp.toArray(new OperationResultVO[0]);
                                return;
                            }
                        }
                    }

                }
            }
        }
    }

    private RuleHeadVO checkValue(RuleQueryVO ruleQueryVO, RuleHeadVO[] rules, AssVO ass) throws BusinessException {
        if (ass.getPk_Checktype() != null && !"".equals(ass.getPk_Checktype())) {
            HashMap<String, AssVO> classID_AssMap = new HashMap();

            for(AssVO assvo : ruleQueryVO.getVO()) {
                classID_AssMap.put(assvo.getM_classid() == null ? AccAssItemCache.getClassIdByAccassItemPK(assvo.getPk_Checktype()) : assvo.getM_classid(), assvo);
            }

            String typeClassID = AccAssItemCache.getClassIdByAccassItemPK(ass.getPk_Checktype());

            try {
                boolean accasoaMatchFlag = false;

                for(RuleHeadVO rule : rules) {
                    accasoaMatchFlag = false;
                    if ((rule.getPk_accountingbook() == null || rule.getPk_accountingbook().equals(ruleQueryVO.getPk_glorgbook()) || rule.getPk_accountingbook().equals(ruleQueryVO.getPk_setofbook())) && rule.getItems() != null && rule.getItems().length > 0 && rule.getBinds() != null && rule.getBinds().length > 0) {
                        for(RuleBindVO bind : rule.getBinds()) {
                            if ("1".equals(bind.getRuletype())) {
                                HashMap<String, String> accMap = new HashMap();
                                accMap.put(ruleQueryVO.getSubject(), ruleQueryVO.getSubject());
                                if (this.checkAccountMatch(ruleQueryVO.getPk_glorgbook(), rule, accMap, bind)) {
                                    accasoaMatchFlag = true;
                                    break;
                                }
                            }
                        }

                        if (accasoaMatchFlag) {
                            HashMap<Integer, String> index_ClassIDMap = new HashMap();
                            HashMap<String, String> valueMap = new HashMap();
                            Method methodTemp = null;
                            Object itemValue = null;

                            for(RuleItemVO item : rule.getItems()) {
                                if (item.getStyleflag().equals("0")) {
                                    for(int i = 1; i < itemSize; ++i) {
                                        methodTemp = item.getClass().getMethod("getItem" + i);
                                        itemValue = methodTemp.invoke(item);
                                        if (itemValue != null && !StringUtils.isEmpty(itemValue.toString())) {
                                            index_ClassIDMap.put(i, itemValue.toString());
                                        }
                                    }
                                }
                            }

                            if (index_ClassIDMap.values().contains(typeClassID)) {
                                String classID = null;
                                String currValue = null;
                                boolean matchFlag = true;

                                for(RuleItemVO item : rule.getItems()) {
                                    if (!item.getStyleflag().equals("0")) {
                                        currValue = null;
                                        matchFlag = true;

                                        for(int i = 1; i < itemSize; ++i) {
                                            classID = (String)index_ClassIDMap.get(i);
                                            if (classID != null) {
                                                methodTemp = item.getClass().getMethod("getItem" + i);
                                                itemValue = methodTemp.invoke(item);
                                                if (itemValue != null && !StrTools.isNullStr(itemValue.toString())) {
                                                    if (classID.equals(typeClassID)) {
                                                        currValue = itemValue.toString();
                                                    } else if (!"ALL".equals(itemValue.toString()) && classID_AssMap.get(classID) != null && !StrTools.isNullStr(((AssVO)classID_AssMap.get(classID)).getPk_Checkvalue()) && !itemValue.toString().equals(((AssVO)classID_AssMap.get(classID)).getPk_Checkvalue())) {
                                                        matchFlag = false;
                                                    }
                                                }
                                            }
                                        }

                                        if (matchFlag) {
                                            valueMap.put(currValue, currValue);
                                        }
                                    }
                                }

                                if (valueMap.get(ass.getPk_Checkvalue()) == null && valueMap.get("ALL") == null) {
                                    return rule;
                                }
                            }
                        }
                    }
                }

                return null;
            } catch (Exception e) {
                Logger.error(e.getMessage(), e);
                throw new BusinessException(e.getMessage(), e);
            }
        } else {
            return null;
        }
    }

    public boolean checkAccountMatch(String pk_accountingbook, RuleHeadVO rule, HashMap<String, String> accMap, RuleBindVO bind) {
        String pk_bindmeta = bind.getPk_bindmeta();
        if ("0001000000ALLACCASOA".equals(pk_bindmeta)) {
            return true;
        } else if (accMap.keySet().contains(pk_bindmeta)) {
            return true;
        } else {
            IGeneralAccessor accessor = GeneralAccessorFactory.getAccessor("407748f1-1fe8-4f0d-880e-ae8b0960308f");
            IBDData docByPk = accessor.getDocByPk(bind.getPk_bindmeta());
            if (docByPk != null) {
                String bindCode = docByPk.getCode();

                for(String str : accMap.keySet()) {
                    IBDData doc = accessor.getDocByPk(str);
                    if (doc != null && doc.getCode().startsWith(bindCode)) {
                        return true;
                    }
                }
            }

            return false;
        }
    }

    private RuleTypeVO[] copyVO(RuleTypeVO[] rtVO, int newCount, boolean b_CopyType) throws RemoteException {
        if (newCount > 0) {
            RuleTypeVO[] ruleVO = new RuleTypeVO[newCount];
            int l_col = 0;

            for(int i = 0; i < rtVO.length; ++i) {
                if (rtVO[i].isOK() == b_CopyType) {
                    ruleVO[l_col] = rtVO[i];
                    ++l_col;
                }
            }

            return ruleVO;
        } else {
            return null;
        }
    }

    public OperationResultVO getAppointValue(RuleQueryVO rqVO) throws BusinessException {
        return null;
    }

    public OperationResultVO getAppointValueBatch(RuleQueryVO rqVO) throws BusinessException {
        return null;
    }

    public OperationResultVO isHaveRule(RuleQueryVO rqVO) throws BusinessException {
        String pk_strCorp = rqVO.getPk_glorgbook();
        String pk_strSubject = rqVO.getSubject();
        String pk_strBook = rqVO.getPk_book();
        String[] pk_strCrossType = rqVO.getPk_StrCrossType();

        try {
            RuleCheckDMO dmo = new RuleCheckDMO();
            RuleTypeVO[] rtVO = dmo.getAllBindRule(pk_strCorp, pk_strSubject, pk_strBook);
            if (rtVO != null && rtVO.length != 0) {
                rtVO = this.checkRuleTypeVO(rtVO, pk_strCrossType);
                if (rtVO != null && rtVO.length > 0) {
                    OperationResultVO ret = new OperationResultVO();
                    ret.m_intSuccess = 0;
                    ret.m_userIdentical = null;
                    return ret;
                } else {
                    OperationResultVO ret = new OperationResultVO();
                    ret.m_intSuccess = 2;
                    ret.m_userIdentical = null;
                    return ret;
                }
            } else {
                OperationResultVO ret = new OperationResultVO();
                ret.m_intSuccess = 2;
                ret.m_userIdentical = null;
                return ret;
            }
        } catch (Exception e) {
            throw new BusinessException(e.getMessage());
        }
    }

    public OperationResultVO[] isLegal(RuleQueryVO scVO) throws BusinessException {
        return null;
    }

    public OperationResultVO[][] isLegalGroupBySubject(RuleQueryVO[] rqVO, HashMap tempaccsubj) throws BusinessException {
        int l_RqVOLen = rqVO.length;
        OperationResultVO[][] ret = new OperationResultVO[l_RqVOLen][];

        try {
            int[] idx = new int[]{0};
            boolean[] order = new boolean[]{true};
            DynamicSort theDynamicSort = new DynamicSort();
            int[] index = theDynamicSort.sort(rqVO, idx, order);
            int begin = 0;

            for(int i = 0; i < l_RqVOLen; ++i) {
                if (i == l_RqVOLen - 1 || rqVO[index[i]].compare(rqVO[index[i + 1]], 0) != 0) {
                    this.isLegals(ret, begin, i, rqVO, index, tempaccsubj);
                    begin = i + 1;
                }
            }
        } catch (Exception e) {
            Log.getInstance(RuleCheckBO.class).error(e);
        }

        return ret;
    }

    private void isLegals(OperationResultVO[][] ret, int begin, int end, RuleQueryVO[] rqVO, int[] idx, HashMap tempaccsubj) throws RemoteException, Exception {
        int t = idx[begin];
        String pk_corp = rqVO[t].getPk_glorgbook();
        String pk_subject = rqVO[t].getSubject();
        String stddate = rqVO[t].getStddate();
        AssVO[] vos = rqVO[t].getVO();
        if (vos != null && vos.length != 0) {
            String[] warning = new String[vos.length];

            for(int i = 0; i < vos.length; ++i) {
                warning[i] = AccAssItemCache.getAccAssitemNameByPK(vos[i].getPk_Checktype());
            }

            AccountVO account = (AccountVO)tempaccsubj.get(pk_subject);
            if (account == null) {
                AccountVO[] accounts = ((IAccountPubService)NCLocator.getInstance().lookup(IAccountPubService.class)).queryAccountVOsByPks(new String[]{pk_subject}, stddate);
                if (accounts == null || accounts.length <= 0) {
                    throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20v61017_0", "020v61017-0265"));
                }

                account = accounts[0];
                tempaccsubj.put(pk_subject, account);
                Vector<AccAssVO> subassvec = AccAssGL.getAccAssVOsByAccount(pk_corp, account, stddate);
                if (subassvec != null && subassvec.size() > 0) {
                    account.setAccass((AccAssVO[])subassvec.toArray(new AccAssVO[0]));
                }
            }

            AccAssVO[] gvo = account.getAccass();
            String pk_unit = null;
            RuleQueryVO voTemp = null;

            for(int k = begin; k <= end; ++k) {
                voTemp = rqVO[idx[k]];
                pk_unit = voTemp.getPk_unit();
                AssVO[] avo = voTemp.getVO();
                Vector v = new Vector();

                for(int i = 0; i < avo.length; ++i) {
                    int j = 0;

                    for(j = 0; j < gvo.length && !avo[i].getPk_Checktype().equals(gvo[j].getPk_entity()); ++j) {
                    }

                    if (j == gvo.length) {
                        throw new BusinessException(NCLangResOnserver.getInstance().getStrByID("200243", "UPP200243-000001"));
                    }

                    IGeneralAccessor acc = GeneralAccessorFactory.getAccessor(avo[i].getM_classid());
                    if (acc.isHaslevel() && !gvo[j].getIsnonleafused().booleanValue() && !acc.isLeaf(pk_unit, avo[i].getPk_Checkvalue())) {
                        boolean isExist = false;
                        IBDData bddata = acc.getDocByPk(avo[i].getPk_Checkvalue());
                        List<IBDData> childs = acc.getChildDocs(bddata.getPk_org(), avo[i].getPk_Checkvalue(), true);
                        if (childs != null) {
                            for(IBDData ibdData : childs) {
                                if (ibdData.getPk().equals(avo[i].getPk_Checkvalue())) {
                                    isExist = true;
                                    break;
                                }
                            }
                        }

                        if (isExist) {
                            OperationResultVO orvo = new OperationResultVO();
                            orvo.m_intSuccess = 2;
                            orvo.m_strPK = avo[i].getPk_Checktype();
                            if (avo[i].getChecktypename() != null && avo[i].getChecktypename().length() != 0) {
                                orvo.m_userIdentical = NCLangResOnserver.getInstance().getStrByID("200243", "UPP200243-000006", (String)null, new String[]{avo[i].getChecktypename()});
                            } else {
                                orvo.m_userIdentical = NCLangResOnserver.getInstance().getStrByID("200243", "UPP200243-000006", (String)null, new String[]{warning[i]});
                            }

                            v.addElement(orvo);
                        }
                    }
                }

                if (v.size() > 0) {
                    OperationResultVO[] tmp = new OperationResultVO[v.size()];

                    for(int l = 0; l < v.size(); ++l) {
                        tmp[l] = (OperationResultVO)v.elementAt(l);
                    }

                    ret[idx[k]] = tmp;
                }
            }

        }
    }

    public OperationResultVO[][] isLegals(RuleQueryVO[] scVO) throws BusinessException {
        int l_scVOLen = scVO.length;
        OperationResultVO[][] ret = new OperationResultVO[l_scVOLen][];

        for(int i = 0; i < l_scVOLen; ++i) {
            ret[i] = this.isLegal(scVO[i]);
        }

        return ret;
    }
}